﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="mis_authorizor.aspx.cs" Inherits="mis_authorizor" EnableEventValidation="false" %>

<%@ Register src="~/UserControls/ucFavorite.ascx" tagname="ucFavorite" tagprefix="Kerry" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
  <script src="../../Scripts/treeview.js"></script>
  <script type="text/javascript">
    var previousSelectedNode = null; //global variable to hold previous selected node
    var previousSelectedNodeClass = null; //global variable to hold previous selected node's class
    function onTreeNodeSelect() {
      if (previousSelectedNode == null) //first time node click
      {
        previousSelectedNode = this;
        previousSelectedNodeClass = this.className;
      }
      else  //deselect previous node
      {
        previousSelectedNode.className = previousSelectedNodeClass;
        previousSelectedNode = this;
      }

      this.className = "nodeSelected";   //setting the style for currently selected node
    }

    window.onload = function () {
      var treeview = document.getElementById("TreeView_Users");
      var nodes = treeview.getElementsByTagName("a");
      for (i = 0; i < nodes.length; i++) {
        if (nodes[i].href == "javascript:void(0);") {
          nodes[i].onclick = onTreeNodeSelect;
        }
      }
    }

  </script>
  <style>
    .nodeSelected {
      background-color: #b1ddf3;
      text-decoration: none;
    }
  </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
  <table class="TableValightTOP">
    <tr><td colspan="3">
      <Kerry:ucFavorite ID="ucFavorite" runat="server"/>功能授權設定</td></tr>
    <tr>
      <td colspan="2">
        <asp:Button ID="btn_save" runat="server" Text="儲存程式授權設定" OnClick="btn_save_Click" />
        <asp:Label ID="lbl_message" runat="server" ForeColor="Blue" EnableViewState="False" />
      </td>      
      <td>
        <asp:Button ID="btn_reload" runat="server" Text="重新整理控制項設定" />
      </td>
    </tr>
    <tr>
      <td>
        <asp:Panel ID="PanelUsers" runat="server" GroupingText="使用者列表" Height="450px" ScrollBars="Vertical">
          部門：<asp:TextBox ID="txt_dept" runat="server" MaxLength="6" Width="70px"></asp:TextBox>
          <br />
          員工：<asp:TextBox ID="txt_userid" runat="server" MaxLength="7" Width="70px"></asp:TextBox>
          (六碼員編)<br />
          <asp:Button ID="btn_search" runat="server" OnClick="btn_search_Click" Text="搜尋" />
          <asp:Label ID="lbl_tvmsg" runat="server" EnableViewState="False" ForeColor="Red" />
          <br />
          <asp:TreeView ID="TreeView_Users" runat="server" ShowLines="True"
            ClientIDMode="Static" OnSelectedNodeChanged="TreeView_Users_SelectedNodeChanged">
            <NodeStyle ImageUrl="~/Images/user.png" />
            <SelectedNodeStyle ForeColor="Red" />
          </asp:TreeView>
        </asp:Panel>
      </td>
      <td>
        <asp:Panel ID="PanelFunction" runat="server" GroupingText="選單功能" Height="450px" ScrollBars="Vertical">
          <asp:TreeView ID="Treeview_Function" runat="server" ClientIDMode="Static"
            ShowLines="True" ShowCheckBoxes="All" OnTreeNodeCheckChanged="Treeview_Function_TreeNodeCheckChanged">
          </asp:TreeView>
        </asp:Panel>
      </td>
      <td>
        <asp:Panel ID="PanelControl" runat="server" GroupingText="控制項" Height="450px" ScrollBars="Both">
          <asp:UpdatePanel ID="up_function_control" runat="server">
            <ContentTemplate>
              <asp:GridView ID="gv_function_control" runat="server" AutoGenerateColumns="False" DataKeyNames="FUNCTION_ID" DataSourceID="SDS_FUNCTION_CONTROL" OnRowDataBound="gv_function_control_RowDataBound">
            <Columns>
              <asp:TemplateField HeaderText="選單功能" SortExpression="FUNCTION_NAME">               
                <ItemTemplate>
                  <asp:Label ID="lbl_function_name" runat="server" Text='<%# Bind("FUNCTION_NAME") %>'/> 
                  (<asp:CheckBox ID="cb_all" runat="server" Text="全選" AutoPostBack="True" OnCheckedChanged="cb_all_CheckedChanged" />)
                </ItemTemplate>
              </asp:TemplateField>
              <asp:TemplateField HeaderText="控制項">
                <ItemTemplate>
                  <asp:Label ID="lbl_function_id" runat="server" Text='<%# Bind("FUNCTION_ID") %>' Visible="false"></asp:Label>                  
                  <asp:CheckBoxList ID="cb_control" runat="server" DataSourceID="SDS_MIS_CONTROL"
                    DataTextField="CONTROL_NAME" DataValueField="CONTROL_ID" RepeatColumns="3">
                  </asp:CheckBoxList>
                  <asp:SqlDataSource ID="SDS_MIS_CONTROL" runat="server"
                    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
                    SelectCommand="SELECT CONTROL_ID, CONTROL_NAME FROM TG.MIS_CONTROL_AP"></asp:SqlDataSource>
                </ItemTemplate>
              </asp:TemplateField>
            </Columns>
          </asp:GridView>
            </ContentTemplate>
          </asp:UpdatePanel>          
          <asp:SqlDataSource ID="SDS_FUNCTION_CONTROL" runat="server"
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
            SelectCommand="SELECT FUNCTION_ID, FUNCTION_NAME FROM TG.MIS_FUNCTION_AP WHERE FUNCTION_TYPE='FUNCTION'  ORDER BY FUNCTION_PARENT_ID  ,FUNCTION_SORT_ORDER "></asp:SqlDataSource>
        </asp:Panel>
      </td>
    </tr>
  </table>
</asp:Content>

